package com.stone.customer.console.trigger;

import com.stone.message.adapter.domain.bo.TriggerMessageParam;
import com.stone.message.adapter.infra.publisher.MessagePublisher;
import com.stone.message.adapter.trigger.AbstractCommonReceiverTrigger;
import com.stone.starter.redis.client.RedisCacheClient;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * redis数据同步抽象同步器
 *
 * @author Mr_wenpan@163.com 2021/07/15 14:55
 */
@Slf4j
@Deprecated
public abstract class AbstractRedisSyncTrigger extends AbstractCommonReceiverTrigger<String, String> {

    /**
     * redis服务客户端
     */
    @Autowired
    private RedisCacheClient redisCacheClient;

    public AbstractRedisSyncTrigger(MessagePublisher messagePublisher) {
        super(messagePublisher);
    }

    @Override
    protected String getData(TriggerMessageParam<String> param) {
        log.info("获取redis数据入参：{}", param);
        return redisCacheClient.opsForList().rightPop(param.getQueryDataParam());
    }

    /**
     * 是否开启多线程执行
     *
     * @return boolean 是则开启多线程，反之则调用线程执行任务
     * @author Mr_wenpan@163.com 2021/7/17 11:07 下午
     */
    @Override
    protected boolean isAsyncExecute() {
        return Boolean.TRUE;
    }

    /**
     * 队列，对应着从Redis中取数据的队列
     *
     * @return java.lang.String
     * @author Mr_wenpan@163.com 2021/7/15 4:20 下午
     */
    protected abstract String queue();
}
